<?php
ini_set("date.timezone", "Asia/Chongqing");

Start::main();

class Start
{
    public static function main()
    {
        $ins=new Start();
        $ins->run();
    }

    private function run()
    {/*{{{*/
        $url="http://host.com:8080/a/b/c.php";
        $url_array=parse_url($url);
        $host=$url_array['host'];
        if(isset($url_array['port']))
            $port=$url_array['port'];
        else
            $port=80;
        $path=$url_array['path'];

        $post="a=1&b=2";
        $length=strlen($post);
        $header="POST $path HTTP/1.1\r\n".
            "Host:$host\n".
            "Content-Type:application/x-www-form-urlencoded\r\n".
            "Content-Length:$length\r\n".
            "Connection:Close\r\n\r\n".
            "$post\r\n";

        $fp=fsockopen($host, $port, $errno, $errstr, 5);
        if($fp === false)
        {
            printf("%s: connect %s:%d fail: %d %s\n",
                    __METHOD__, $host, $port, $errno, $errstr);
            return;
        }
        fputs($fp, $header);
        stream_set_timeout($fp, 10);
        $inheader=true;
        $response="";
        while(!feof($fp))
        {
            $line=fgets($fp);
            if($inheader && ($line == "\n" || $line == "\r\n"))
                $inheader=false;
            if(!$inheader)
                $response.=$line;
        }
        fclose($fp);

        print $response."\n";
    }/*}}}*/
}
?>
